package com.chiyi.controller;

import com.chiyi.bean.TProduct;
import com.chiyi.mapper.TProductMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @date 2021/5/13 17:40
 */
@RestController
@Api(tags = "商品")
@RequestMapping("/product")
@Slf4j
public class ProductController {

    @Resource
    private TProductMapper tProductMapper;


    @ApiOperation("查询商品信息")
    @GetMapping("/detail/{id}")
    public TProduct detail(@PathVariable Integer id) {
        TProduct tProduct = tProductMapper.selectById(id);
        tProduct.setStock(tProduct.getStock() - 1);
        tProduct.updateById();
        log.info("商品信息：{}", tProduct);
        return tProduct;
    }

}
